﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using IkeCode.WP7.HQReader.Interfaces;
using System.Runtime.Serialization;
using System.Windows.Media.Imaging;
using Newtonsoft.Json;

namespace IkeCode.WP7.HQReader.Model
{
    /// <summary>
    /// Model for Publishers, implements IIcFeedPublisher
    /// </summary>
    /// <see cref="IkeCode.WP7.HQReader.Interfaces.IIcFeedPublisher"/>
    [JsonObject(MemberSerialization.OptIn)]
    public sealed class IcFeedPublisherModel : IcBaseModel, IIcFeedPublisher
    {
        #region Fields

        Uri _url;
        int _newestCount;
        bool _isPinned;

        #endregion Fields

        #region Interface Fields

        /// <summary>
        /// Publisher Url
        /// </summary>
        [JsonProperty(PropertyName = "Url")]
        public Uri Url
        {
            get { return this._url; }
            set { this._url = value; }
        }
        
        /// <summary>
        /// Newest feeds count
        /// </summary>
        [JsonProperty(PropertyName = "NewestCount")]
        public int NewestCount
        {
            get { return this._newestCount; }
            set { this._newestCount = value; }
        }

        /// <summary>
        /// Is pinned flag
        /// </summary>
        [JsonProperty(PropertyName = "IsPinned")]
        public bool IsPinned
        {
            get { return this._isPinned; }
            set { this._isPinned = value; }
        }

        #endregion Interface Fields

        #region Constructors

        /// <summary>
        /// Default constructor
        /// </summary>
        public IcFeedPublisherModel() 
        {
            this.Id = Guid.NewGuid();
            this.InsertDate = DateTime.Now;
        }

        /// <summary>
        /// Constructor with bindings
        /// </summary>
        /// <param name="url">Publisher url</param>
        /// <param name="title">Publisher name</param>
        /// <param name="newestCount">Newest feeds count</param>
        public IcFeedPublisherModel(Uri url, string title, int newestCount) : this ()
        {
            this.Url = url;
            this.Title = title;
            this.UniqueId = MD5Core.GetHashString(this.Title);
            this.NewestCount = newestCount;
        }

        /// <summary>
        /// Constructor with bindings
        /// </summary>
        /// <param name="id">Id</param>
        /// <param name="url">Publisher url</param>
        /// <param name="title">Publisher name</param>
        /// <param name="newestCount">Newest feeds count</param>
        public IcFeedPublisherModel(Guid id, Uri url, string title, int newestCount)
            : this(url, title, newestCount)
        {
            this.Id = id;
            this.UniqueId = MD5Core.GetHashString(this.Title);
        }

        #endregion
    }
}
